﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Xml.Serialization;
using Microsoft.Win32;
using WK35705XML.Annotations;

namespace WK35705XML
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        private UMPs umps = new UMPs();

        public MainWindow()
        {
            InitializeComponent();
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var u = await UMPHelp.OpenUMPFile();
            umps = u;
        }

        public UMPs Umps
        {
            get { return umps; } set { umps = value;
                OnPropertyChanged("Umps");
            }}

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged( string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }

        private async void Save(object sender, RoutedEventArgs e)
        {
            if(!Umps.Items.Any())
                return;

            await UMPHelp.SaveUMP(Umps);
        }



        private void AddUMP(object sender, RoutedEventArgs e)
        {
            if(Umps == null)
                umps = new UMPs();
            if (Umps.Items == null)
                umps.Items = new ObservableCollection<UMP>();
            umps.Items.Add(new UMP(){name = "new UMP"});

        }

    }
}
